cmake_minimum_required(VERSION 3.10)

project(openHiTLS_Provider)

set(CMAKE_C_STANDARD 99)

set(OPENHITLS_DIR /openhitls)
set(WD_DIR /usr/local/include/warpdrive)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")

include_directories(

    ${OPENHITLS_DIR}/include/bsl
    ${OPENHITLS_DIR}/config/macro_config
    ${OPENHITLS_DIR}/platform/Secure_C/include
    ${OPENHITLS_DIR}/bsl/log/include
    ${OPENHITLS_DIR}/bsl/err/include
    ${OPENHITLS_DIR}/include/crypto
    ${OPENHITLS_DIR}/crypto/include
    ${OPENHITLS_DIR}/include/tls
    ${OPENHITLS_DIR}/bsl/sal/include
    ${OPENHITLS_DIR}/bsl/asn1/include
    ${OPENHITLS_DIR}/bsl/base64/include
    ${OPENHITLS_DIR}/bsl/buffer/include
    ${OPENHITLS_DIR}/bsl/hash/include
    ${OPENHITLS_DIR}/bsl/list/include
    ${OPENHITLS_DIR}/bsl/obj/include
    ${OPENHITLS_DIR}/bsl/pem/include
    ${OPENHITLS_DIR}/bsl/tlv/include
    ${OPENHITLS_DIR}/bsl/uio/include
    ${OPENHITLS_DIR}/crypto/bn/include
    ${OPENHITLS_DIR}/crypto/aes/include
    ${OPENHITLS_DIR}/crypto/sm4/include
    ${OPENHITLS_DIR}/crypto/chacha20/include
    ${OPENHITLS_DIR}/crypto/drbg/include
    ${OPENHITLS_DIR}/crypto/ealinit/include
    ${OPENHITLS_DIR}/crypto/eal/src
    ${OPENHITLS_DIR}/crypto/hkdf/include
    ${OPENHITLS_DIR}/crypto/sha3/include
    ${OPENHITLS_DIR}/crypto/ecdsa/include
    ${OPENHITLS_DIR}/crypto/ecdh/include
    ${OPENHITLS_DIR}/crypto/curve25519/include
    ${OPENHITLS_DIR}/crypto/encode/include
    ${OPENHITLS_DIR}/crypto/dsa/include
    ${OPENHITLS_DIR}/crypto/dh/include
    ${OPENHITLS_DIR}/crypto/rsa/include
    ${OPENHITLS_DIR}/crypto/scrypt/include
    ${OPENHITLS_DIR}/crypto/entropy/include
    ${OPENHITLS_DIR}/crypto/paillier/include
    ${OPENHITLS_DIR}/crypto/sha2/include
    ${OPENHITLS_DIR}/crypto/hmac/include
    ${OPENHITLS_DIR}/crypto/md5/include
    ${OPENHITLS_DIR}/crypto/sm3/include

    ${WD_DIR}
    ${WD_DIR}/include

    ${CMAKE_SOURCE_DIR}/alg/cipher/
    ${CMAKE_SOURCE_DIR}/alg/digests/
    ${CMAKE_SOURCE_DIR}/alg/pkey/include/
    ${CMAKE_SOURCE_DIR}/alg/dh/include/
    ${CMAKE_SOURCE_DIR}/provider
    ${CMAKE_SOURCE_DIR}/utils/

)

add_definitions(
    -DHITLS_BSL_ERR
    -DHITLS_BSL_LOG
    -DHITLS_BSL_SAL_MEM
    -DHITLS_BSL_SAL_LOCK
    -DHITLS_BSL_SAL_THREAD
    -DHITLS_BSL_SAL_TIME
    -DHITLS_BSL_SAL_FILE
    -DHITLS_BSL_SAL_NET
    -DHITLS_BSL_SAL_STR
    -DHITLS_BSL_SAL_DL
    -DHITLS_BSL_SAL_LINUX
    -DHITLS_BSL_INIT
    -DHITLS_CRYPTO_HMAC
    -DHITLS_CRYPTO_MD
    -DHITLS_CRYPTO_ENTROPY
    -DHITLS_CRYPTO_DRBG
    -DHITLS_CRYPTO_PKEY
    -DHITLS_CRYPTO_BN
    -DHITLS_THIRTY_TWO_BITS
    -DHITLS_SIXTY_FOUR_BITS
)

set(SRCS
    ${CMAKE_SOURCE_DIR}/alg/cipher/modes.c
    ${CMAKE_SOURCE_DIR}/alg/digests/digests.c
    ${CMAKE_SOURCE_DIR}/alg/dh/src/dh.c
    ${CMAKE_SOURCE_DIR}/alg/dh/src/dh_keygen.c
    ${CMAKE_SOURCE_DIR}/alg/pkey/src/rsa.c
    ${CMAKE_SOURCE_DIR}/alg/pkey/src/rsa_keygen.c

    ${CMAKE_SOURCE_DIR}/provider/cipher.c
    ${CMAKE_SOURCE_DIR}/provider/keyexch.c
    ${CMAKE_SOURCE_DIR}/provider/keymgmt.c
    ${CMAKE_SOURCE_DIR}/provider/md.c
    ${CMAKE_SOURCE_DIR}/provider/pkey.c
    ${CMAKE_SOURCE_DIR}/provider/provider.c
    ${CMAKE_SOURCE_DIR}/provider/sign.c
)

set(LIBRARIES hitls_bsl hitls_crypto boundscheck pthread wd)

add_library(${PROJECT_NAME} SHARED ${SRCS})
target_link_libraries(${PROJECT_NAME} ${LIBRARIES})

target_compile_definitions(${PROJECT_NAME} PUBLIC
    __FILENAME__=__FILE__
)
